﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace FangDuShi_API.Common
{
    /// <summary>
    /// 常用的正则判断
    /// </summary>
    public class RegExp
    {
        #region 判断字符串是否由数字组成
        /// <summary>
        /// 判断字符串是否由数字组成
        /// </summary>
        public static bool IsNumeric(string s)
        {
            string pattern = @"^\-?[0-9]+$";
            return Regex.IsMatch(s, pattern);
        }
        #endregion
        #region 判断字符串是否存在操作数据库的安全隐患
        /// <summary>
        /// 判断字符串是否存在操作数据库的安全隐患
        /// </summary>
        public static bool IsSafety(string s)
        {
            string str = s.Replace("%20", " ");
            str = Regex.Replace(str, @"\s", " ");
            string pattern = @"select |insert |delete from |count\(|drop table|update |truncate |asc\(|mid\(|char\(|xp_cmdshell|exec master|net localgroup administrators|:|net user|""|\'| or ";
            return !Regex.IsMatch(str, pattern, RegexOptions.IgnoreCase);
        }
        #endregion
    }
}
